package io.kimmking.dubbo.common.balance.impl;

import cn.hutool.core.collection.CollectionUtil;
import io.kimmking.dubbo.common.balance.LoadBalance;

import java.util.List;

public abstract class AbstractLoadBalance implements LoadBalance {

    protected abstract String doSelect(List<String> upstreamList, String from_ip) throws Exception;

    @Override
    public String select(final List<String> upstreamList, String from_ip) throws Exception {
        if (CollectionUtil.isEmpty(upstreamList))
            return null;
        if (upstreamList.size() == 1)
            return upstreamList.get(0);

        return doSelect(upstreamList, from_ip);
    }
}